package json
{
	import adobejson.JSON;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	
	public class SimpleReport extends Sprite
	{
		private var str:String;
		private var text:TextField;
		
		private var space:String = "\n=============================================================\n";
		public function SimpleReport()
		{
			stage.align = StageAlign.TOP;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			text = new TextField();
			text.width = 500;
			text.height = 1000;
			text.multiline = true;
			text.wordWrap = true;
			this.addChild(text);
			init();
			explain();
		}
		
		public function init():void {
			str ="["+ 
					"[" +
						//对战双方资料
						"[" +
							"['赵冠义','贝贝','338:185','.72','37591250','0','228845'],"+
							"['曹操','赤壁大战','0:0','0','43200000','0','0']"+
						"],"+
						//人员列表
						"["+
							//攻方
							"["+
								"['神司马懿','虎豹骑','20000','20000','128875'],"+
								"['神曹操','虎豹骑','20000','3560','497169']"+
							"],"+
							//受方
							"["+
								"['曹操','龙骑兵','30000','30000','0'],"+
								"['诸葛果','羽林军','30000','30000','0']"+
							"]"+
						"],"+
						//战斗中发动技能
						"["+
							//攻方
							"["+
								
							"],"+
							//受方
							"["+
								"['诸葛果','小月斩'],"+
								"['庞统','强回复']"+
							"]"+
						"],"+
						
						//战斗中发动召唤兽
						"["+
						//攻方
							"["+
								"['神貂蝉','凤凰']"+
							"],"+
						//受方
							"["+
								
							"]"+
						"],"+
						//战斗结果
						"['1','5224100','4810325','6114075','850400','','','','诸葛果','汗血马']"+
					"]"+
					
					
					
					/*"[" +
					//对战双方资料
					"[" +
					"['赵冠义','贝贝','338:185','.72','37591250','0','228845'],"+
					"['曹操','赤壁大战','0:0','0','43200000','0','0']"+
					"],"+
					//人员列表
					"["+
					//攻方
					"["+
					"['神司马懿','虎豹骑','20000','20000','128875'],"+
					"['神曹操','虎豹骑','20000','3560','497169']"+
					"],"+
					//受方
					"["+
					"['曹操','龙骑兵','30000','30000','0'],"+
					"['诸葛果','羽林军','30000','30000','0']"+
					"]"+
					"],"+
					//战斗中发动技能
					"["+
					//攻方
					"["+
					
					"],"+
					//受方
					"["+
					"['诸葛果','小月斩'],"+
					"['庞统','强回复']"+
					"]"+
					"],"+
					
					//战斗中发动召唤兽
					"["+
					//攻方
					"["+
					"['神貂蝉','凤凰']"+
					"],"+
					//受方
					"["+
					
					"]"+
					"],"+
					//战斗结果
					"['1','5224100','4810325','6114075','850400','','','','诸葛果','汗血马']"+
					"]"+*/
				"]";
		}
		
		public function explain():void {
			str = str.replace(new RegExp("\'","g"), "\"");
			var arr:Array = JSON.decode(str);
			str = "";
			for(var n:int=0;n<arr.length;n++) {
				
				var attackGen:String = "<b>"+"攻方部队"+"</b>\n";
				var defendGen:String = "\n<b>"+"守方部队"+"</b>\n";
				
				var attackReply:String = "";
				var defendReply:String = "";
				
				var attackGenExp:String = "\n<b>"+"攻方武将"+":</b>\n";
				var defendGenExp:String = "\n<b>"+"守方武将"+":</b>\n";
				
				var attackDieArms:int = 0;//战死总数
				var defendDieArms:int = 0;
				
				var attackReplyRate:Number = arr[n][0][0][3];
				var defendReplyRate:Number = arr[n][0][1][3];
				
				str += "攻击方："+arr[n][0][0][0]+"["+arr[n][0][0][1]+"]"+"["+arr[n][0][0][2]+"]武将：";
				
				for(var i:int=0;i<arr[n][1][0].length;i++) {//攻方武将
					str += (i==arr[n][1][0].length-1)?arr[n][1][0][i][0]:(arr[n][1][0][i][0]+" , ");
					//死兵
					var genStr:String = arr[n][1][0][i][0]+"("+arr[n][1][0][i][1]+":"+arr[n][1][0][i][2]+" - "+arr[n][1][0][i][3]+" = "+(arr[n][1][0][i][2]-arr[n][1][0][i][3])+")";
					attackGen += (i==arr[n][1][0].length-1)?genStr:(genStr+" , ");
					//死兵回复
					var attackReplyTemp:String = arr[n][1][0][i][0]+"("+arr[n][1][0][i][1]+"+"+int(arr[n][1][0][i][3]*attackReplyRate)+")";
					attackReply += (i==arr[n][1][0].length-1)?attackReplyTemp:(attackReplyTemp+" , ");
					//死兵总数
					attackDieArms += int(arr[n][1][0][i][3]);
					//武将经验
					attackGenExp += (i==arr[n][1][0].length-1)?(arr[n][1][0][i][0]+"+"+arr[n][1][0][i][4]):((arr[n][1][0][i][0]+"+"+arr[n][1][0][i][4])+" , ");
				}
				str += "\n"+"防守方："+arr[n][0][1][0]+"["+arr[n][0][1][1]+"]"+"["+arr[n][0][1][2]+"]武将：";
				
				for(var i:int=0;i<arr[n][1][1].length;i++) {//守方
					str += (i==arr[n][1][1].length-1)?arr[n][1][1][i][0]:(arr[n][1][1][i][0]+" , ");
					var genStr:String = arr[n][1][1][i][0]+"("+arr[n][1][1][i][1]+":"+arr[n][1][1][i][2]+" - "+arr[n][1][1][i][3]+" = "+(arr[n][1][1][i][2]-arr[n][1][1][i][3])+")";
					defendGen += (i==arr[n][1][1].length-1)?genStr:(genStr+" , ");
					
					var defendReplyTemp:String = arr[n][1][1][i][0]+"("+arr[n][1][1][i][1]+"+"+int(arr[n][1][1][i][3]*defendReplyRate)+")";
					defendReply += (i==arr[n][1][1].length-1)?defendReplyTemp:(defendReplyTemp+" , ");
					
					defendDieArms += int(arr[n][1][1][i][3]);
					
					//武将经验
					defendGenExp += (i==arr[n][1][1].length-1)?(arr[n][1][1][i][0]+"+"+arr[n][1][1][i][4]):((arr[n][1][1][i][0]+"+"+arr[n][1][1][i][4])+" , ");
				}
				str += space;
				
				str += "<b>"+"战斗结果 : "+"<font color='#ff0000'>"+((arr[n][4][0]==1)?"攻击方胜利！":(arr[n][4][0]==2)?"平局！":"防守方胜利！")+"</font></b>";
				str += "\n"+"缴获资源：粮食："+arr[n][4][1]+" 木材："+ arr[n][4][2]+" 铁矿："+ arr[n][4][3]+" 黄金："+ arr[n][4][4];
				str += "\n"+"战斗损失：攻击方："+arr[n][0][0][4]+"(单位)"+"防守方："+arr[n][0][1][4]+"(单位)";
				str += "\n"+"战斗最终损失：攻击方："+arr[n][0][0][5]+"(单位)"+"防守方："+arr[n][0][1][5]+"(单位)";
				str += space;
				//
				str += attackGen + defendGen;
				str += "\n\n";
				
				str +=  "<b>"+"战斗中俘虏武将"+"</b>\n";
				str += "俘虏了武将:"+arr[n][4][8]+","+"请在酒馆中查看";
				
				str += "\n";
				str +=  "<b>"+"战斗中俘虏坐骑"+"</b>\n";
				str += "俘虏了坐骑:"+arr[n][4][9]+","+"请在马市中查看";
				
				str += space;
				str += "<b>"+"战斗后回复士兵"+"</b>";
				trace(attackDieArms+"................."+defendDieArms);
				str += "\n<b>"+"攻方部队" + ":["+"回复"+ int(attackDieArms*attackReplyRate)+"人"+"]["+"回复率"+":"+attackReplyRate*100+"%]" + "</b>\n"+
						attackReply +
						"\n<b>"+"守方部队" + ":["+"回复"+ int(defendDieArms*defendReplyRate)+"人"+"]["+"回复率"+":"+defendReplyRate*100+"%]" + "</b>\n"+
						defendReply;
				str += space;
				
				str += "<b>"+"战斗后武将获得经验值"+"</b>";
				str += attackGenExp + defendGenExp;
				
				str += space;
				str += "<b>"+"战斗中武将发动技能"+"</b>\n"+"<b>"+"攻方武将"+":</b>";
				for(var attackSkill:int=0;attackSkill<arr[n][2][0].length;attackSkill++) {
					if(attackSkill==0) str+="\n";
					var attackSkillTemp:String = arr[n][2][0][attackSkill][0]+"("+arr[n][2][0][attackSkill][1]+")";
					str += (attackSkill==arr[n][2][0].length-1)?attackSkillTemp:(attackSkillTemp+" , ");
				}
				str += "\n<b>"+"守方武将"+":</b>";
				for(var defendSkill:int=0;defendSkill<arr[n][2][1].length;defendSkill++) {
					if(defendSkill==0) str+="\n";
					var defendSkillTemp:String = arr[n][2][1][defendSkill][0]+"("+arr[n][2][1][defendSkill][1]+")";
					str += (defendSkill==arr[n][2][1].length-1)?defendSkillTemp:(defendSkillTemp+" , ");
				}
				
				str += space;
				str += "<b>"+"战斗中武将发动召唤兽"+"</b>\n"+"<b>"+"攻方武将"+":</b>";
				for(var attackPet:int=0;attackPet<arr[n][3][0].length;attackPet++) {
					if(attackPet==0) str+="\n";
					var attackPetTemp:String = arr[n][3][0][attackPet][0]+"("+arr[n][3][0][attackPet][1]+")";
					str += (attackPet==arr[n][3][0].length-1)?attackPetTemp:(attackPetTemp+" , ");
				}
				str += "\n<b>"+"守方武将"+":</b>";
				for(var defendPet:int=0;defendPet<arr[n][3][1].length;defendPet++) {
					if(defendPet==0) str+="\n";
					var defendPetTemp:String = arr[n][3][1][defendPet][0]+"("+arr[n][3][1][defendPet][1]+")";
					str += (defendPet==arr[n][3][1].length-1)?defendPetTemp:(defendPetTemp+" , ");
				}
				
				str += space;
				str += "<b>"+"战斗后玩家获得声望"+"</b>\n";
				str += arr[n][0][0][0]+"获得声望"+":"+arr[n][0][0][6]+"\n"+arr[n][0][1][0]+"获得声望"+":"+arr[n][0][1][6];
				trace(str);
				text.htmlText = str;
			}
		}
	}
}